package com.eoner.managerlibrary.netsign.core;

import com.eoner.managerlibrary.netsign.NetEnvManager;
import com.eoner.managerlibrary.netsign.version1.GetCookiesInterceptor;
import com.eoner.managerlibrary.netsign.version2.FCSignInterceptor;
import com.eoner.managerlibrary.netsign.version2.HttpInterceptor2;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * 文件名：FCRetrofitManager
 * 描 述：只处理(v1)新接口请求入口
 * 作 者：gyq
 * 时 间：2021-2-22
 */
public class FCRetrofitManager {

    private Retrofit mRetrofit;

    private static FCRetrofitManager instance;
    public static FCRetrofitManager getInstance() {
        synchronized (FCRetrofitManager.class) {
            if (instance == null) {
                instance = new FCRetrofitManager();
            }
        }
        return instance;
    }

    private FCRetrofitManager() {
        //声明日志类
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        //设定日志级别
        httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);//NONE
        //自定义OkHttpClient
        OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
        //添加拦截器
        okHttpClient.addInterceptor(new GetCookiesInterceptor());
        //添加签名
        okHttpClient.addInterceptor(new HttpInterceptor2());
        //添加请求头
        okHttpClient.addInterceptor(new FCSignInterceptor());
        okHttpClient.addInterceptor(httpLoggingInterceptor);
        mRetrofit = new Retrofit.Builder()
                .baseUrl(NetEnvManager.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create()).client(okHttpClient.build()).build();

    }

    public Retrofit getRetrofit() {
        return mRetrofit;
    }


}
